import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routes= [
		// 首页
		{
			path: '/Home',
			name: 'home',
			component: ()=>import('./views/Home.vue'),
			redirect:'/Welcome',
			children:[
				// 欢迎页
				{
					path:"/Welcome",
					name:'welcome',
					component:()=>import('./views/Welcome.vue')
				},
				// 用户管理
				{
					path:"/users",
					name:'user',
					component:()=>import('./components/User/user.vue')
				},
				// 权限管理
				{
					path:"/roles",
					name:'role',
					component:()=>import('./components/Roles/roles.vue')
				},
				// 权限列表
				{
					path:"/rights",
					name:'rights',
					component:()=>import('./components/Roles/rights.vue')
				},
				// 商品列表
				{
					path:"/goods",
					name:'goods',
					component:()=>import('./components/Goods/goods.vue')
				},
				// 添加商品
				{
					path:"/addGoods",
					name:'addGoods',
					component:()=>import('./components/Goods/addGoods.vue')
				},
				// 分类参数
				{
					path:"/params",
					name:'params',
					component:()=>import('./components/Goods/params.vue')
				},
				// 商品分类
				{
					path:"/categories",
					name:'categories',
					component:()=>import('./components/Goods/categories.vue')
				},
				// 订单列表
				{
					path:"/orders",
					name:'orders',
					component:()=>import('./components/Orders/orders.vue')
				},
				// 数据统计
				{
					path:"/reports",
					name:'reports',
					component:()=>import('./components/Reports/reports.vue')
				}
			]
		},
		// 登录
		{
			path: '/Login',
			name: "login",
			component: () => import('./views/Login.vue')
		},
	]
const router =new Router({
	routes
})
// 全局路由守卫
router.beforeEach((to,from,next)=>{
		if(to.name!=='login'&&!sessionStorage.getItem('token')){
			next('/')
		}else if(to.name==='login'&&sessionStorage.getItem('token')){
			next('/Home')
		}else{
			next();
		}
	})
export default router